var currentPage = 1;//当前页码
var pageSize = 5;//每页显示的数据量
var totalCount = 0;//总条数
var totalPage = 1;//总页码

//加载分页信息
function pageInfo() {
    //渲染表头
    $(".myTable2").html("<tr><td colspan='11' style='color: #009E94;font-size: 15px;font-weight: bold'>简历信息列表</td>" +
        "</tr>" +
        "<tr>"+
        "<th >姓名</th>" +
        "<th >性别</th>" +
        "<th >毕业院校</th>" +
        "<th >学历</th>" +
        "<th >专业</th>" +
        "<th >应聘职位</th>" +
        "<th >工作年限</th>" +
        "<th >登记日期</th>" +
        "<th >简历状态</th>" +
        "<th >修改简历状态</th>" +
        "<th >操作</th></tr>")
    //整理后台需要的参数
    let jsonA = {
        reName1: $(".reName1").val().trim(),
        posName: $(".posName").val().trim(),
        workEx: $(".workEx").val().trim(),
        resState: $(".resState").val().trim(),
        recommendTime: $(".recommendTime").val().trim(),
        currentPage: currentPage,
        pageSize: pageSize
    };

    //发送到后台
    $.ajaxSettings.async = false;
    $.getJSON("/fc/mianshiguanli",jsonA, function (dataA) {
        console.log(dataA)
        //总条数
        totalCount = dataA.total;
        //总页数
        totalPage = dataA.pages;

        if (totalPage!=0) {
            //获取回调后渲染数据
            $(dataA.list).each(function (i, v) {
                let a;
                if (v.resState == "推荐面试") {
                    a = "<select onchange='tanchuang(" + v.id + ",this)' class='sele' style='width: 100%'>" +
                        "<option value=''>" + "请选择" + "</option>" +
                        "<option value='推荐面试' disabled='disabled'>" + "推荐面试" + "</option>" +
                        "<option value='推荐二面' style='color: #14e98d'>" + "推荐二面" + "</option>" +
                        "<option value='推荐三面' disabled='disabled'>" + "推荐三面" + "</option>" +
                        "<option value='建议录用' disabled='disabled'>" + "建议录用" + "</option>" +
                        "</select>"
                }
                if (v.resState == "推荐二面") {
                    a = "<select onchange='tanchuang(" + v.id + ",this)' class='sele' style='width: 100%'>" +
                        "<option value=''>" + "请选择" + "</option>" +
                        "<option value='推荐面试' disabled='disabled'>" + "推荐面试" + "</option>" +
                        "<option value='推荐二面' disabled='disabled'>" + "推荐二面" + "</option>" +
                        "<option value='推荐三面' style='color: #14e98d'>" + "推荐三面" + "</option>" +
                        "<option value='建议录用' disabled='disabled'>" + "建议录用" + "</option>" +
                        "</select>"
                }
                if (v.resState == "推荐三面") {
                    a = "<select onchange='tanchuang(" + v.id + ",this)' class='sele' style='width: 100%'>" +
                        "<option value=''>" + "请选择" + "</option>" +
                        "<option value='推荐面试' disabled='disabled'>" + "推荐面试" + "</option>" +
                        "<option value='推荐二面' disabled='disabled'>" + "推荐二面" + "</option>" +
                        "<option value='推荐三面' disabled='disabled'>" + "推荐三面" + "</option>" +
                        "<option value='建议录用' style='color: #14e98d'>" + "建议录用" + "</option>" +
                        "</select>"
                }
                let feny = "<tr>" +
                    "<td>" + v.reName1 + "</td>" +
                    "<td>" + v.reSex + "</td>" +
                    "<td>" + v.schoolTag + "</td>" +
                    "<td>" + v.education + "</td>" +
                    "<td>" + v.major + "</td>" +
                    "<td>" + v.position.posName + "</td>" +
                    "<td>" + v.workEx + "</td>" +
                    "<td>" + v.recommendTime + "</td>" +
                    "<td class='statusNow'>" + v.resState + "</td>" +
                    "<td>" + a + "</td>" +
                    "<td>" + "<a href='/fc/mianshidengji/" + v.id + "'>" + "<button style='width:100px' class='layui-btn layui-btn-normal'>" + "面试结果登记" + "</button>" + "</a>" + "&nbsp;" + "&nbsp;" +
                    "<a href='/fc/mingxi/" + v.id + "'>" + "<button style='width:70px' class='layui-btn layui-btn-normal' >" + "明细" + "</button>" + "</a>" + "&nbsp;" + "&nbsp;" +
                    "<a href='#'>" + "<button style='width:70px' class='layui-btn layui-btn-danger' onclick='del(" + v.id + ",this)'>" + "删除" + "</button>" + "</a>" +
                    "</td>" +
                    "</tr>";
                $(".myTable2").append(feny);
            })
        }else{
            totalPage=1;
            currentPage=1;
            layer.alert('未查到符合条件的简历信息', {
                skin: 'layui-layer-molv' //样式类名  自定义样式
                ,closeBtn: 1    // 是否显示关闭按钮
                ,anim: 1 //动画类型
                ,icon: 6    // icon
                ,time:1500
                ,area: ['400px', '200px']
            });
        }
    })
    $.ajaxSettings.async = true;

    //调用页数
    showPage()
}


//模糊查询按钮点击事件
function moHuSel() {
    //防止出现2/1的情况
    currentPage = 1;
    //分页查看数据
    pageInfo();
    //以下判断防止“0数据”，出现1/0的情况！收尾工作
    if (totalCount == 0) {
        totalPage = 1;
        $(".showPage").text(currentPage + "/" + totalPage);

    }
}


//录用页面删除按钮
function del(id,thisA) {
    //抓取当前简历状态
    let status= $(thisA).parents("td").prev().prev().text();
    layer.alert('确定要删除当前信息吗？', {
        skin: 'layui-layer-molv' //样式类名  自定义样式
        ,closeBtn: 1    // 是否显示关闭按钮
        ,anim: 1 //动画类型
        ,btn: ['确定','取消'] //按钮
        ,icon: 6    // icon
        ,area: ['400px', '200px']
        ,yes:function(){
            layer.closeAll();
            let jsonA = {
                id: id,
                resState:status
            }
            $.ajaxSettings.async = false;
            $.getJSON("del1", jsonA, function (dataA) {
                if (dataA == true) {
                    $(thisA).parents("tr").remove();

                        layer.alert('删除成功！', {
                            skin: 'layui-layer-molv' //样式类名  自定义样式
                            , closeBtn: 1    // 是否显示关闭按钮
                            , anim: 1 //动画类型
                            , btn: ['确定'] //按钮
                            , icon: 6    // icon
                            , area: ['400px', '200px']
                            , yes: function () {
                                if (totalCount % pageSize == 1) {
                                    currentPage -= 1;
                                }
                                showPage();
                                if(totalCount==0){
                                    location.reload();
                                    return;
                                }
                                pageInfo();
                                layer.closeAll();

                            }
                        });

                } else {
                    layer.alert('删除失败！', {
                        skin: 'layui-layer-molv' //样式类名  自定义样式
                        ,closeBtn: 1    // 是否显示关闭按钮
                        ,anim: 1 //动画类型
                        ,btn: ['确定'] //按钮
                        ,icon: 6    // icon
                        ,area: ['400px', '200px']
                        ,yes:function(){
                            layer.closeAll();
                        }
                    });
                    return;
                }
            })
            $.ajaxSettings.async = true;
        }
        ,btn2:function () {
            layer.close();
        }
    });


}



//下拉框点击后弹层抓值到后台做修改操作
function tanchuang(id,thiA) {
    let abc = $(thiA).val()
    if(abc=="推荐二面"){
        layer.open({
            title: '一面面试结果登记'
            ,content: '<table class="layui-table myTable3">\n' +
                '        <tr>\n' +
                '            <td>一面面试人：</td>\n' +
                '            <td><input type="text" class="layui-input firstMianPeople" value="系统管理员" readonly></td>\n' +
                '            <td>面试时间：</td>\n' +
                '            <td><input type="text" class="layui-input firstMianTime" value="" readonly></td>\n' +
                '        </tr>\n' +
                '        <tr>\n' +
                '            <td width="20%">一面面试评价：</td>\n' +
                '            <td colspan="3"> <textarea class="layui-input firstMianAppraise" name="firstMianAppraise"></textarea></td>\n' +
                '        </tr>\n' +
                '    </table>',
            area: ['600px', '300px'],
            skin: 'layui-layer-molv', 			//注意这里，靠这个css自定义样式！！！！！
            btn:["确定","取消"],
            success:function(){//弹出层弹出后回调
                //获取当前日期
                let myDate = new Date();
                //赋值给时间
                $(".firstMianTime").val( myDate.toLocaleDateString());
                $('.layui-layer-setwin').hide();
            },
            btn1:function(){//确定事件

                let firstMianPeople = $(".firstMianPeople").val();
                let firstMianAppraise = $(".firstMianAppraise").val();

                let jsonA={
                    id:id,
                    resState:abc,
                    firstMianPeople:firstMianPeople,
                    firstMianAppraise,firstMianAppraise
                }

                $.ajaxSettings.async = false;
                $.post("addmianshijieguo01", jsonA, function (dataA) {
                    if (dataA == true) {
                        layer.alert('简历状态修改成功！', {
                            skin: 'layui-layer-molv' //样式类名  自定义样式
                            ,closeBtn: 1    // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: ['确定'] //按钮
                            ,icon: 6    // icon
                            ,area: ['400px', '200px']
                            ,yes:function(){
                                if(totalCount%pageSize==1){
                                    currentPage-=1;
                                }
                                showPage();
                                pageInfo();
                                layer.closeAll();
                            }
                        });
                    } else {
                        layer.alert('简历状态修改失败！', {
                            skin: 'layui-layer-molv' //样式类名  自定义样式
                            ,closeBtn: 1    // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: ['确定'] //按钮
                            ,icon: 5    // icon
                            ,area: ['400px', '200px']
                            ,yes:function(){
                                layer.closeAll();
                            }
                        });
                        return;
                    }
                },"JSON")
                $.ajaxSettings.async = true;
            },
            btn2:function(){//取消事件
                $(thiA).val("");
            }
        });
    }else if(abc=="推荐三面"){
        layer.open({
            title: '二面面试结果登记'
            ,content: '<table class="layui-table myTable3">\n' +
                '        <tr>\n' +
                '            <td>二面面试人：</td>\n' +
                '            <td><input type="text" class="layui-input secondMianPeople" value="系统管理员" readonly></td>\n' +
                '            <td>面试时间：</td>\n' +
                '            <td><input type="text" class="layui-input secondMianTime" readonly></td>\n' +
                '        </tr>\n' +
                '        <tr>\n' +
                '            <td width="20%">二面面试评价：</td>\n' +
                '            <td colspan="3"> <textarea class="layui-input secondMianAppraise" name="secondMianAppraise"></textarea></td>\n' +
                '        </tr>\n' +
                '    </table>',
            area: ['600px', '300px'],
            skin: 'layui-layer-molv', 			//注意这里，靠这个css自定义样式！！！！！
            btn:["确定","取消"],
            success:function(){//弹出层弹出后回调
                //获取当前日期
                let myDate = new Date();
                //赋值给时间
                $(".secondMianTime").val(myDate.toLocaleDateString());
                $('.layui-layer-setwin').hide();
            },
            btn1:function(){//确定事件
                let secondMianPeople = $(".secondMianPeople").val();
                let secondMianAppraise = $(".secondMianAppraise").val();

                let jsonA={
                    id:id,
                    resState:abc,
                    secondMianPeople:secondMianPeople,
                    secondMianAppraise,secondMianAppraise
                }

                $.ajaxSettings.async = false;
                $.post("addmianshijieguo02", jsonA, function (dataA) {
                    if (dataA == true) {
                        layer.alert('简历状态修改成功！', {
                            skin: 'layui-layer-molv' //样式类名  自定义样式
                            ,closeBtn: 1    // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: ['确定'] //按钮
                            ,icon: 6    // icon
                            ,area: ['400px', '200px']
                            ,yes:function(){
                                if(totalCount%pageSize==1){
                                    currentPage-=1;
                                }
                                showPage();
                                pageInfo();
                                layer.closeAll();
                            }
                        });
                    } else {
                        layer.alert('简历状态修改失败！', {
                            skin: 'layui-layer-molv' //样式类名  自定义样式
                            ,closeBtn: 1    // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: ['确定'] //按钮
                            ,icon: 5    // icon
                            ,area: ['400px', '200px']
                            ,yes:function(){
                                layer.closeAll();
                            }
                        });
                        return;
                    }
                },"JSON");
                $.ajaxSettings.async = true;
            },
            btn2:function(){//取消事件
                $(thiA).val("");
            }
        });
    }else if(abc=="建议录用"){
        layer.open({
            title: '三面面试结果登记'
            ,content: '<table class="layui-table myTable3">\n' +
                '        <tr>\n' +
                '            <td>三面面试人：</td>\n' +
                '            <td><input type="text" class="layui-input thirdMianPeople" value="系统管理员" readonly></td>\n' +
                '            <td>面试时间：</td>\n' +
                '            <td><input type="text" class="layui-input thirdMianTime" readonly></td>\n' +
                '        </tr>\n' +
                '        <tr>\n' +
                '            <td width="20%">三面面试评价：</td>\n' +
                '            <td colspan="3"> <textarea class="layui-input thirdMianAppraise" name="thirdMianAppraise"></textarea></td>\n' +
                '        </tr>\n' +
                '    </table>',
            area: ['600px', '300px'],
            skin: 'layui-layer-molv', 			//注意这里，靠这个css自定义样式！！！！！
            btn:["确定","取消"],
            success:function(){//弹出层弹出后回调
                //获取当前日期
                let myDate = new Date();
                //赋值给时间
                $(".thirdMianTime").val( myDate.toLocaleDateString());
                $('.layui-layer-setwin').hide();
            },
            btn1:function(){//确定事件
                let thirdMianPeople = $(".thirdMianPeople").val();
                let thirdMianAppraise = $(".thirdMianAppraise").val();

                let jsonA={
                    id:id,
                    resState:abc,
                    thirdMianPeople:thirdMianPeople,
                    thirdMianAppraise,thirdMianAppraise
                }

                $.ajaxSettings.async = false;
                $.post("addmianshijieguo03", jsonA, function (dataA) {
                    if (dataA == true) {
                        $(thiA).parents("tr").remove();

                            layer.alert('简历状态修改成功！', {
                                skin: 'layui-layer-molv' //样式类名  自定义样式
                                , closeBtn: 1    // 是否显示关闭按钮
                                , anim: 1 //动画类型
                                , btn: ['确定'] //按钮
                                , icon: 6    // icon
                                , area: ['400px', '200px']
                                , yes: function () {
                                    if (totalCount % pageSize == 1) {
                                        currentPage -= 1;
                                    }
                                    showPage();
                                    pageInfo();
                                    layer.closeAll();
                                }
                            });

                    } else {
                        layer.alert('简历状态修改失败！', {
                            skin: 'layui-layer-molv' //样式类名  自定义样式
                            ,closeBtn: 1    // 是否显示关闭按钮
                            ,anim: 1 //动画类型
                            ,btn: ['确定'] //按钮
                            ,icon: 5    // icon
                            ,area: ['400px', '200px']
                            ,yes:function(){
                                layer.closeAll();
                            }
                        });
                        return;
                    }
                },"JSON")
                $.ajaxSettings.async = true;
            },
            btn2:function(){//取消事件
                $(thiA).val("");
            }
        });
    }
}


//展示页码
function showPage() {

    if(totalPage==0){
        totalPage=1;
    }
    if(currentPage==0){
        currentPage=1;
    }
    $(".showPage").text("第" + currentPage + "页 / 共" + totalPage + "页");
}

//下一页
function next() {
    currentPage++;
    if (currentPage > totalPage) {
        currentPage = totalPage;
        return;
    }
    pageInfo();
}


//上一页
function prev() {
    currentPage--;
    if (currentPage < 1) {
        currentPage = 1;
        return;
    }
    pageInfo();
}

//首页
function start() {
    currentPage = 1;
    pageInfo();
}

//尾页
function end() {
    currentPage = totalPage;
    pageInfo();
}




